package com.c.yinyuezhushou.Dialog;


import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.cardview.widget.CardView;

import com.c.yinyuezhushou.MRetrofit.MusicItem;
import com.c.yinyuezhushou.MyApplication;
import com.c.yinyuezhushou.R;
import com.c.yinyuezhushou.Service.DownService;

public class DownDialog extends AlertDialog {
    boolean cancelable;
    Context context;
    MusicItem musicItem;

    public DownDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener,MusicItem musicItem) {
        super(context, cancelable, cancelListener);
        this.cancelable = cancelable;
        this.context = context;
        this.musicItem = musicItem;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.dialog_down);

        setCancelable(cancelable);
        Window window = getWindow();
        window.setBackgroundDrawableResource(R.color.touming);

        WindowManager.LayoutParams params = window.getAttributes();

        params.gravity = Gravity.CENTER;

        window.setAttributes(params);

        CardView cardView1 = findViewById(R.id.dd_card1);
        CardView cardView2 = findViewById(R.id.dd_card2);
        CardView cardView3 = findViewById(R.id.dd_card3);
        CardView cardView4 = findViewById(R.id.dd_card4);

        MyApplication myApplication = (MyApplication) context.getApplicationContext();
        DownService downService = myApplication.getDownService();

        cardView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                downService.downloadMusicItem(musicItem,128000);
                Toast.makeText(downService, "正在飞速下载中...", Toast.LENGTH_SHORT).show();
                DownDialog.this.dismiss();
            }
        });
        cardView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                downService.downloadMusicItem(musicItem,192000);
                Toast.makeText(downService, "正在飞速下载中...", Toast.LENGTH_SHORT).show();
                DownDialog.this.dismiss();
            }
        });
        cardView3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                downService.downloadMusicItem(musicItem,320000);
                Toast.makeText(downService, "正在飞速下载中...", Toast.LENGTH_SHORT).show();
                DownDialog.this.dismiss();
            }
        });
        cardView4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                downService.downloadMusicItem(musicItem,990000);
                Toast.makeText(downService, "正在飞速下载中...", Toast.LENGTH_SHORT).show();
                DownDialog.this.dismiss();
            }
        });

    }
}
